package com.gack.business.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gack.business.model.RequestModel;
import com.gack.business.service.OperatorManagerServiceInterface;
import com.gack.helper.common.AjaxJson;
import com.gack.helper.common.abstractobj.ApiController;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(ApiController.OPERATOR_MANAGER)
public class OperatorManagerController {
	
	@Autowired
	private OperatorManagerServiceInterface operatorManagerServiceInterface;
	
	@ApiOperation("保存背景图片")
	@PostMapping("/saveBackgroundPicture")
	public AjaxJson saveBackgroundPicture(String uid, String picture) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorManagerServiceInterface.saveBackgroundPicture(uid, picture));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation("获取背景图片")
	@PostMapping("/getAllBackgroundPicture")
	public AjaxJson getAllBackgroundPicture() {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorManagerServiceInterface.getAllBackgroundPicture());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation("保存管理员信息")
	@PostMapping("/saveManagerInfo")
	public AjaxJson saveManagerInfo(String uid, String phone, String email) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorManagerServiceInterface.saveManagerInfo(uid, phone, email));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation("获取管理员信息")
	@PostMapping("/getAllManagerInfo")
	public AjaxJson getAllManagerInfo() {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorManagerServiceInterface.getAllManagerInfo());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation("保存友情链接")
	@PostMapping("/saveFriendShip")
	public AjaxJson saveFriendShip(@RequestBody RequestModel requestModel) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorManagerServiceInterface.saveFriendShip(requestModel.getUid(), requestModel));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation("获取友情链接")
	@PostMapping("/getAllFriendShip")
	public AjaxJson getAllFriendShip() {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorManagerServiceInterface.getAllFriendShip());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation("运营后台首页获取全部数据")
	@PostMapping("/getAllData")
	public AjaxJson getAllData() {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorManagerServiceInterface.getAllData());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
	

}
